import MySQLdb
import config
import datetime
import time
from datetime import date
from time import mktime

def create_conn():
    conn = MySQLdb.connect (host=config.host_mysql,
                            user=config.user_mysql,
                            passwd=config.pass_mysql,
                            db=config.db_mysql,
                            port=config.port_mysql,
                            charset='utf8',
                            use_unicode=False,
                            )
    conn.autocommit(True)
    return conn

def get_timeunix_today():
    mydate = date.today()
    return int(mktime(mydate.timetuple()))
def get_datetime(time_unix):
    return (datetime.datetime.fromtimestamp(int(time_unix)).strftime('%d-%m-%Y'))

def get_result_sql(conn,cmd):
    try:
        conn.ping()
    except:
        conn = create_conn()
    cursor = conn.cursor(MySQLdb.cursors.DictCursor)
    cursor.execute(cmd)
    result = cursor.fetchall()
    cursor.close()
    return result

def get_current_date(time_date):
    return(datetime.datetime.fromtimestamp(int(time_date)).strftime('%d-%m-%Y'))
    (datetime.datetime.fromtimestamp(int(time.time())))
    

    
if __name__ == '__main__':
    #conn = create_conn()
    import datetime
    print datetime.datetime


    
    
    
    
                      